﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using RhythmComet.Physics;
using FMOD;
using RhythmComet.Services;
using RhythmComet.Particles;
using System.Collections.Generic;
using System;
using RhythmComet.Utils;

namespace RhythmComet
{
    public interface ITitleIntroState : IGameState { }

    public sealed class TitleIntroState : GameState, ITitleIntroState
    {
        private Texture2D background;
        private SpriteFont font;
        private Vector2 backgroundPosition;
        private Vector2 titlePosition;

        private AlertMessage alertMessage;

        public TitleIntroState(RhythmCometGame game)
            : base(game)
        {
            game.Services.AddService(typeof(ITitleIntroState), this);

            alertMessage = new AlertMessage(0.8f);
        }

        public override void Update(GameTime gameTime)
        {
            if (Input.GamePadState.Buttons.Back == ButtonState.Pressed)
                game.Exit();

#if !XBOX
            if (Input.WasPressed(Buttons.Start) || Input.WasPressed(Keys.Enter))
#else
            if (Input.WasPressed(Buttons.Start))
#endif
            {
                GameManager.PushState(game.StartMenuState.Value);
            }

            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            game.GraphicsDevice.Clear(Color.Black);

            string message = "INSERT COIN";
            Vector2 fontOrign = font.MeasureString(message) / 2;
            Vector2 position = new Vector2(game.SpriteBatch.GraphicsDevice.Viewport.Width / 2, game.SpriteBatch.GraphicsDevice.Viewport.Height / 2 + 100);
            alertMessage.Draw(message, position - fontOrign, gameTime, game.SpriteBatch, font);

            game.SpriteBatch.Begin();
            game.SpriteBatch.Draw(background, backgroundPosition, Color.White);
            game.SpriteBatch.End();

            base.Draw(gameTime);
        }

        protected override void LoadContent()
        {
            background = game.Content.Load<Texture2D>("sprites/titleBackground");
            font = game.Content.Load<SpriteFont>(@"fonts\GridExercise");
            backgroundPosition = new Vector2((game.GraphicsDevice.Viewport.Width / 2 - background.Width / 2),
                (game.GraphicsDevice.Viewport.Height / 2 - background.Height / 2));
            titlePosition = new Vector2((game.GraphicsDevice.Viewport.Width / 2 - 100),
                (game.GraphicsDevice.Viewport.Height / 2));
        }
    }
}
